#Boa:Frame:FUModificar

import wx
import psycopg2
import psycopg2.extras
import sys
import pprint
from FUModificar2 import FUModificar2

def create(parent):
    return FUModificar(parent)

[wxID_FUMODIFICAR, wxID_FUMODIFICARBMENU, wxID_FUMODIFICARBMODIFICAR, 
 wxID_FUMODIFICARCODIGO, wxID_FUMODIFICARPANEL1, wxID_FUMODIFICARTEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(6)]

Codigo=''

def select_usuario(cod):
  conn_string = "host='localhost' port='5432' dbname='DB778' user='postgres' password='123456789'"
  conn = psycopg2.connect(conn_string)
  cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  "DELETE from catedratico where codigo_catedratico = "+cod
  consulmod = "SELECT codigo_catedratico, nombre, id_tipo FROM catedratico WHERE codigo_catedratico = "+cod
  cursor.execute(consulmod)
  rows = cursor.fetchall()

  for row in rows:
      #print str(row["nombre"]) + str(row["id_tipo"])
      framep1=FUModificar2(None,cod,str(row["nombre"]),str(row["id_tipo"]))
      framep1.Show(True)
  conn.close()


class FUModificar(wx.Frame):
    codigo=''
    Codigo_catedratico=0
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FUMODIFICAR, name=u'FUModificar',
              parent=prnt, pos=wx.Point(506, 167), size=wx.Size(300, 220),
              style=wx.DEFAULT_FRAME_STYLE, title=u'Modificar Usuario')
        self.SetClientSize(wx.Size(300, 220))

        self.panel1 = wx.Panel(id=wxID_FUMODIFICARPANEL1, name='panel1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(300, 220),
              style=wx.TAB_TRAVERSAL)

        self.bmenu = wx.Button(id=wxID_FUMODIFICARBMENU, label=u'Menu',
              name=u'bmenu', parent=self.panel1, pos=wx.Point(40, 168),
              size=wx.Size(105, 40), style=0)
        self.bmenu.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'Sans'))
        self.bmenu.Bind(wx.EVT_BUTTON, self.OnBmenuButton,
              id=wxID_FUMODIFICARBMENU)

        self.bmodificar = wx.Button(id=wxID_FUMODIFICARBMODIFICAR,
              label=u'Modificar', name=u'bmodificar', parent=self.panel1,
              pos=wx.Point(185, 105), size=wx.Size(105, 40), style=0)
        self.bmodificar.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'Sans'))
        self.bmodificar.Bind(wx.EVT_BUTTON, self.OnBmodificarButton,
              id=wxID_FUMODIFICARBMODIFICAR)

        self.Codigo = wx.StaticText(id=wxID_FUMODIFICARCODIGO, label=u'Codigo',
              name=u'Codigo', parent=self.panel1, pos=wx.Point(24, 54),
              size=wx.Size(66, 18), style=0)
        self.Codigo.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'Sans'))

        self.textCtrl1 = wx.TextCtrl(id=wxID_FUMODIFICARTEXTCTRL1,
              name='textCtrl1', parent=self.panel1, pos=wx.Point(105, 48),
              size=wx.Size(180, 30), style=0, value=u'')
        self.textCtrl1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Sans'))

    def __init__(self, parent,cod):
        global codigo
        global Codigo_catedratico
        codigo=cod
        Codigo_catedratico=cod
        self._init_ctrls(parent)

    def OnBmenuButton(self, event):
        self.Close(True)
        event.Skip()

    def OnBmodificarButton(self, event):
      Codigo = self.textCtrl1.GetValue ()
      print Codigo
      if Codigo!= '':
          select_usuario(Codigo)
      self.textCtrl1.SetValue('') 
